package com.xh.one2one.base.service.impl;

import com.xh.one2one.base.bean.request.OneSchoolRequest;
import com.xh.one2one.base.dao.OneSchoolMapper;
import com.xh.one2one.base.model.OneSchool;
import com.xh.core.service.impl.BaseServiceImpl;
import com.xh.one2one.base.service.IOneSchoolService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.core.bean.XhPage;
import com.xh.core.util.StringUtils;
import java.util.List;
/**
 * <p>
 * 校区 服务实现类
 * </p>
 *
 * @author TW
 * @since 2021-05-17
 */
@Service
public class OneSchoolServiceImpl extends BaseServiceImpl<OneSchoolMapper, OneSchool> implements IOneSchoolService {
    @Override
    public XhPage querySchoolPage(XhPage page, OneSchoolRequest bean) {
        QueryWrapper qw=new QueryWrapper<OneSchool>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List querySchool(OneSchoolRequest bean) {
        QueryWrapper qw=new QueryWrapper<OneSchool>();
        //拼装条件
        qw=prepareParams(bean, qw);
        if(!StringUtils.isEmpty(bean.getSchoolName())){
            qw.like("school_name",bean.getSchoolName());
        }

        return this.dao.selectList(qw);
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(OneSchoolRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        return qw;
    }
}
